package gjtx3;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class SetCompany {
    private String companyName;
    private String site;
    private String phone;
    private String manage;
    Staff st = new Staff();
    Set set=new TreeSet();

    public SetCompany(String companyName, String site, String phone, String manage) {
        this.companyName = companyName;
        this.site = site;
        this.phone = phone;
        this.manage = manage;
    }

    public SetCompany() {
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getManage() {
        return manage;
    }

    public void setManage(String manage) {
        this.manage = manage;
    }

    public void show() {
        System.out.println("公司:" + companyName + "地址在" + site);
    }

    //招聘员工（要求工号不能重复）(在员工类中重写equals方法！！！)
    public boolean recruit(String name, int nianL, String xingB, String zhiW, int xinShui, String number) {
        st = new Staff(name, nianL, xingB, zhiW, xinShui, number);
        for (Object s : set) {
            if (s.equals(st))
                return false;
        }
        set.add(st);
        System.out.println("已招聘！ ");
        return true;
    }

    //输出员工信息
    public void output() {
        System.out.println("员工信息如下：");
        for (Object a : set)
            System.out.println(a);
    }

    //辞退员工
    public boolean delete(String number) {
        for (Object s:set) {
            Staff a = (Staff)s;
            if (a.getNumber().equals(number)) {
                set.remove(a);
                System.out.println("已辞退！");
                return true;
            }
        }
        System.out.println("未找到！");
        return false;
    }

    public void statistics() {
        System.out.println("总共有" + set.size() + "人。");
    }

    public Staff salary() {
        if (set.size() > 0) {
            Iterator it=set.iterator();
            System.out.println(it.next());
            return (Staff) it.next();
        }
        System.out.println("未找到！");
        return null;
    }
}

